package com.annotation.demo5;

/**
 * @ClassName Breeder
 * @Description 饲养员
 * @Author Kx
 * @Date 2025/3/30 16:13
 * @Version 1.0
 */
public class Breeder<T extends Animal> {
    public String name;
    private T animal;

    public Breeder() {

    }
    public Breeder(String name, T animal) {
        this.name = name;
        this.animal = animal;
    }

    /***
     * @author: kx
     * @date: 2025/3/30 16:14
     * @description: 饲养员的喂养方法
    */
    public void feed(){
        System.out.println(name + "开始喂食");
        // 调用动物的eat方法
        animal.eat();
    }

    /***
     * @author: kx
     * @date: 2025/3/30 16:32
     * @description: 饲养员检查动物随眠情况
    */
    public void patrol(){
        System.out.println(name + "开始巡查");
        // 判断动物是否有睡眠注解
        if (animal.getClass().isAnnotationPresent(Sleep.class)) {
            // 获取睡眠注解的实例
            Sleep sleep = animal.getClass().getAnnotation(Sleep.class);

            // 判断睡眠注解的值是否为健康
            if (sleep.value().equals("健康")) {
                System.out.println(animal + "睡眠正常");
            } else {
                System.out.println(animal + "需要吃安眠药");
            }
        }
    }

    /***
     * @author: kx
     * @date: 2025/3/30 16:35
     * @description: 检查动物健康情况
    */
    public void healthCheck(){
        System.out.println(name + "开始健康检查");
        // 判断动物是否有健康注解
        if (animal.getClass().isAnnotationPresent(Health.class)) {
            // 获取健康注解的实例
            Health annotation = animal.getClass().getAnnotation(Health.class);

            // 判断健康注解的值是否为差
            if (annotation.value().equals("差")) {
                System.out.println(animal + "需要重点照看");
            } else {
                System.out.println(animal + "健康状况良好");
            }
        }
    }
}
